$OpenBSD: patch-erlang-js-spidermonkey_c,v 1.2 2013/03/26 05:26:30 jmatthew Exp $

Cope with API change between bundled spidermonkey 1.8 and external 1.9.
Use JS_SetOperationCallback instead of JS_SetBranchCallback to perform
periodic gc, and fix some compiler warnings in the call to JS_DefineFunction.

--- deps/erlang_js/c_src/spidermonkey.c.orig	Wed Jan 30 06:13:01 2013
+++ deps/erlang_js/c_src/spidermonkey.c	Sat Feb 23 10:27:33 2013
@@ -78,19 +78,19 @@ void on_error(JSContext *context, const char *message,
   }
 }
 
-JSBool on_branch(JSContext *context, JSScript *script) {
+JSBool on_operation(JSContext *context) {
   JSBool return_value = JS_TRUE;
   spidermonkey_state *state = (spidermonkey_state *) JS_GetContextPrivate(context);
-  state->branch_count++;
+  state->operation_count++;
 
   if (state->terminate)  {
       return_value = JS_FALSE;
   }
-  else if (state->branch_count == 550) {
+  else if (state->operation_count == 550) {
     JS_GC(context);
-    state->branch_count = 0;
+    state->operation_count = 0;
   }
-  else if(state->branch_count % 100 == 0) {
+  else if(state->operation_count % 100 == 0) {
     JS_MaybeGC(context);
   }
 
@@ -140,7 +140,7 @@ void sm_configure_locale(void) {
 spidermonkey_vm *sm_initialize(long thread_stack, long heap_size) {
   spidermonkey_vm *vm = ejs_alloc(sizeof(spidermonkey_vm));
   spidermonkey_state *state = ejs_alloc(sizeof(spidermonkey_state));
-  state->branch_count = 0;
+  state->operation_count = 0;
   state->error = NULL;
   state->terminate = 0;
   int gc_size = (int) heap_size * 0.25;
@@ -158,10 +158,9 @@ spidermonkey_vm *sm_initialize(long thread_stack, long
   vm->global = JS_NewObject(vm->context, &global_class, NULL, NULL);
   JS_InitStandardClasses(vm->context, vm->global);
   JS_SetErrorReporter(vm->context, on_error);
-  JS_SetBranchCallback(vm->context, on_branch);
+  JS_SetOperationCallback(vm->context, on_operation);
   JS_SetContextPrivate(vm->context, state);
-  JSNative funptr = (JSNative) &js_log;
-  JS_DefineFunction(vm->context, JS_GetGlobalObject(vm->context), "ejsLog", funptr,
+  JS_DefineFunction(vm->context, JS_GetGlobalObject(vm->context), "ejsLog", (JSNative)js_log,
                     0, JSFUN_FAST_NATIVE);
   end_request(vm);
 
